package name.marz.to.go.ahg.mhbk.gui;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class SecretQADialog extends JDialog implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JButton btnOK;
	private JButton btnCancel;
	private JTextField textAnswer;
	
	public enum Result {
		OK,Cancel
	}
	private Result result;
	
	public SecretQADialog(String question,String title) {
		super();
		setTitle(title);
		setLayout(new FlowLayout());
		btnOK = new JButton("OK");
		btnOK.addActionListener(this);
		btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(this);
		textAnswer = new JTextField(10);
		add(new JLabel(question));
		add(textAnswer);
		add(btnOK);
		add(btnCancel);
		setSize(300, 200);
		setModal(true);
	}

	public Result showDialog() {
		setVisible(true);
		return result;
	}
	
	public String getAnswer() {
		return textAnswer.getText();
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if ( e.getSource() == btnOK ) {
			result = Result.OK;
			dispose();
		} else if ( e.getSource() == btnCancel ) {
			result = Result.Cancel;
			dispose();
		}
	}
	
	public static void main(String[] args) {
		new SecretQADialog("testtesttest","合言葉１").showDialog();
		System.out.println("show end");
	}

}
